import 'package:flutter/material.dart';
import 'package:flutter_app/bean/respon.dart';
import 'package:flutter_app/api/api.dart' as api;

class ContentPage extends StatefulWidget {
  final OneInfo _info;

  ContentPage(this._info);

  @override
  ContentPageState createState() {
    return new ContentPageState(_info);
  }
}

class ContentPageState extends State<ContentPage> {
  OneInfo _info;

  ContentPageState(this._info);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(_info.title),
      ),
      body: new ListView(
        children: <Widget>[
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: _getItem(),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.collections),
        onPressed: () {
          api.collectionInfo(_onCollection, _info.id);
        },
      ),
    );
  }

  _getItem() {
    var item = <Widget>[];
    if (_info.chapterName != null) {
      item.add(Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Text(
          "文章类别:" + _info.chapterName,
          style: new TextStyle(fontSize: 19.0),
        ),
      ));
    }
    if (_info.superChapterName != null) {
      item.add(
        new Container(
          padding: const EdgeInsets.only(
              left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
          child: new Text(
            "开发环境:" + _info.superChapterName,
            style: new TextStyle(fontSize: 19.0),
          ),
        ),
      );
    }
    if (_info.niceDate != null) {
      item.add(new Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Text(
          "发布时间:" + _info.niceDate,
          style: new TextStyle(fontSize: 19.0),
        ),
      ));
    }
    if (_info.desc != null) {
      item.add(new Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Text("文章简介:" + _info.desc),
      ));
    }
    if (_info.link != null && _info.link != "") {
      item.add(new Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Text("文章链接:" + _info.link),
      ));
    }
    if (_info.projectLink != null && _info.projectLink != "") {
      item.add(new Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Text("项目链接:" + _info.projectLink),
      ));
    }
    if (_info.envelopePic != null && _info.envelopePic != "") {
      item.add(new Container(
        padding: const EdgeInsets.only(
            left: 10.0, right: 10.0, top: 4.0, bottom: 4.0),
        child: new Image.network(_info.envelopePic),
      ));
    }
    return item;
  }

  void _onCollection(data) {
    print(data);
  }

  @override
  void initState() {
    super.initState();
  }
}
